import java.util.Arrays;
import java.util.Comparator;

class Student /*implements Comparable<Student>*/ {
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student = {" +
                name + ", " + age
                + ", " + score +
                "} ;";
    }
}
//比较器
class AgeCompare implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class ScoreCompare implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2){
        return o1.score - o2.score;
    }
}
class NameCompare implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2){
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void main(String[] args){
        Student[] student = new Student[3];
        student[0] = new Student("张三",19,90);
        student[1] = new Student("李四",17,82);
        student[2] = new Student("王五",18,85);
        System.out.println("排序前:" + Arrays.toString(student));
        Arrays.sort(student,new ScoreCompare());
        System.out.println("排序后:" + Arrays.toString(student));

    }
    public static void main3(String[] args){

        Student student1 = new Student("张三",19,90);
        Student student2 = new Student("李四",17,82);
        ScoreCompare scoreCmopare = new ScoreCompare();
        if(scoreCmopare.compare(student1, student2) > 0){
            System.out.println("student1 > student2");
        }
    }
    public static void main2(String[] args){
        Student[] student = new Student[3];
         student[0] = new Student("张三",19,90);
         student[1] = new Student("李四",17,82);
         student[2] = new Student("王五",18,85);
        System.out.println("排序前:" + Arrays.toString(student));
        Arrays.sort(student);
        System.out.println("排序后:" + Arrays.toString(student));

    }
/*    public static void main1(String[] args){
        Student student1 = new Student("张三",19,90);
        Student student2 = new Student("李四",18,82);
        if(student1.compareTo(student2) > 0){
            System.out.println("student1 > student2");
        }
    }*/
}
